<!DOCTYPE html>
<html>
<head>
  <title>编辑帖子</title>
   <#include "../common/link.ftl">
</head>
<body>

<#include "../common/header.ftl">

<div class="layui-container fly-marginTop">
  <div class="fly-panel" pad20 style="padding-top: 5px;">
    <!--<div class="fly-none">没有权限</div>-->
    <div class="layui-form layui-form-pane">
      <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title">
          <li class="layui-this">编辑帖子</li>
        </ul>
        <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <form action="" method="post">
              <div class="layui-row layui-col-space15 layui-form-item">
                <div class="layui-col-md3">
                  <label class="layui-form-label">所在专栏</label>
                  <div class="layui-input-block">
                    <@shiro.hasRole name="admin">
                          <select lay-verify="required" id="topic" name="topic" lay-filter="column">
                              <option></option>
                              <#if (post.topic!'')=='0' >
                                  <option selected value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option value="169">动态</option>
                              <#elseif (post.topic!'')=='99'>
                                  <option value="0">提问</option>
                                  <option selected value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option value="169">动态</option>
                              <#elseif (post.topic!'')=='100'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option selected value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option value="169">动态</option>
                              <#elseif (post.topic!'')=='101'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option selected value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option value="169">动态</option>
                              <#elseif (post.topic!'')=='168'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="169">动态</option>
                                  <option selected value="168">公告</option>
                              <#elseif (post.topic!'')=='169'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option selected value="169">动态</option>
                              <#else >
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                                  <option value="168">公告</option>
                                  <option value="169">动态</option>
                              </#if>
                          </select>
                    </@shiro.hasRole>
                      <@shiro.hasRole name="member">
                          <select lay-verify="required" id="topic" name="topic" lay-filter="column">
                              <option></option>
                              <#if (post.topic!'')=='0' >
                                  <option selected value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                              <#elseif (post.topic!'')=='99'>
                                  <option value="0">提问</option>
                                  <option selected value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                              <#elseif (post.topic!'')=='100'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option selected value="100">讨论</option>
                                  <option value="101">建议</option>
                              <#elseif (post.topic!'')=='101'>
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option selected value="101">建议</option>
                              <#else >
                                  <option value="0">提问</option>
                                  <option value="99">分享</option>
                                  <option value="100">讨论</option>
                                  <option value="101">建议</option>
                              </#if>
                          </select>
                      </@shiro.hasRole>
                  </div>
                </div>
                <div class="layui-col-md9">
                  <label for="title" class="layui-form-label">标题</label>
                  <div class="layui-input-block">
                    <input type="text" id="title" name="title" value="${post.title!''}" required lay-verify="required" autocomplete="off" class="layui-input">
                  </div>
                </div>
              </div>

              <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">
                  <textarea id="content" name="content" required lay-verify="required" placeholder="详细描述" class="layui-textarea fly-editor" style="height: 260px;">${post.content!''}</textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">悬赏财富</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <select name="treasure" id="treasure" readonly="readonly">
                      <#if (post.treasure!'') == 20>
                          <option selected value="20">20</option>
                      <#elseif (post.treasure!'') == 30>
                          <option selected value="30">30</option>
                      <#elseif (post.treasure!'') == 30>
                          <option selected value="50">50</option>
                      <#elseif (post.treasure!'') == 50>
                          <option selected value="60">60</option>
                      <#elseif (post.treasure!'') == 60>
                          <option selected value="80">80</option>
                      <#else>
                          <option value="20">20</option>
                          <option value="30">30</option>
                          <option value="50">50</option>
                          <option value="60">60</option>
                          <option value="80">80</option>
                      </#if>

                    </select>
                  </div>
                  <div class="layui-form-mid layui-word-aux">发表后无法更改财富</div>
                </div>
              </div>
              <div class="layui-form-item">
                <label for="authcode" class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                  <input type="text" id="authcode" name="authcode" required lay-verify="required" placeholder="请回答后面的问题" autocomplete="off" class="layui-input">
                </div>
                <div class="">
                    <img class="pointer" id="code_img" src="${ctx.contextPath}/authcode/calculate" alt="点击刷新"/>
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" lay-filter="*" lay-submit id="update_btn">确认修改</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<#include "../common/footer.ftl">

<script>
layui.cache.page = 'jie';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: '${ctx.contextPath}/static/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "3.0.0"
  ,base: '${ctx.contextPath}/static/mods/'
}).extend({
  fly: 'index'
}).use(['fly','form'], function () {
    var layer = layui.layer, $ = layui.$, form = layui.form;
    //刷新验证码
    $("#code_img").on("click", function () {
        $(this).attr("src" ,  "${ctx.contextPath}/authcode/calculate?t=" + $.now());
    });

    //监听提交
    form.on('submit(*)', function(data){
        return false;
    });

    $("#update_btn").on("click", function () {
        var topic_dom = $("#topic"), title_dom = $("#title"), authcode_dom = $("#authcode")
                ,content_dom = $("#content"), treasure_dom = $("#treasure");
        if (!mq.verify_val(topic_dom) || !mq.verify_val(title_dom) || !mq.verify_val(authcode_dom)
                || !mq.verify_val(content_dom) || !mq.verify_val(treasure_dom)) {
            return false;
        }
        var index = layer.load(), ctx = "${ctx.contextPath}", url = ctx + "/post/updatePost",
                data = {_id:${post._id!''}, topic:topic_dom.val(),title:title_dom.val(),content:content_dom.val(),
                    treasure:treasure_dom.val(), authcode:authcode_dom.val()};
        mq.async(url, data, ctx, index);
        setTimeout(function () {
            $("#code_img").click();
        }, 200);
    });

});
</script>

</body>
</html>